<div class="bg-light lter b-b wrapper-md">
  <h1 class="m-n font-thin h3">转码方案管理</h1>
</div>

<div class="wrapper-md"  >
  <div class="panel panel-default">
    <div ng-controller="infoEditCtrl">
      <div class="row">
        <div class="col-sm-12" >
        <form name="form-contact" ng-submit="processForm()" class="form-horizontal">
          <div class="panel-heading">
            <span class="h4">
              <button class="btn btn-default btn-sm " ng-click="goBack()"><i class="fa fa-mail-reply fa-lg"></i>&nbsp; 返回</button>
            </span>

          </div>
            <div class="panel-body">
              <div class="panel-heading">
                <span class="h4" style="color: blue;">转码方案信息</span>
              </div>
              
              <div class="form-group">
                <label  class="col-sm-1 control-label">模板名称</label>
                <div class="col-sm-5">
                <input type="text" class="form-control" placeholder="模板名称" ng-model="contact.TemplateName">
                </div>
              </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>

            <div class="form-group">
              <label class="col-sm-1 control-label">启用状态</label>
             <div class="col-sm-5">
              <select class="form-control " ng-model="contact.TemplateEnable" required >
               <option ng-repeat="x in TemplateEnables" value="{{x.value}}">{{x.key}}</option>
              </select>
             </div>

              <label class="col-sm-1 control-label">自动转码</label>
             <div class="col-sm-5">
              <select class="form-control " ng-model="contact.AutoTranscode" required >
               <option ng-repeat="x in AutoTranscodes" value="{{x.value}}">{{x.key}}</option>
              </select>
             </div>
            </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>



            <div class="form-group">
              <label class="col-sm-1 control-label">视频清晰度</label>
              <div class="col-sm-5">
               <select class="form-control " ng-model="contact.VideoDefinition" required >
               <option ng-repeat="x in VideoDefinitions" value="{{x.value}}">{{x.key}}</option>
              </select>
              </div>
              <label  class="col-sm-1 control-label">优先级</label>
              <div class="col-sm-5">
                <select class="form-control " ng-model="contact.TaskPriority" required >
               <option ng-repeat="x in TaskPrioritys" value="{{x.value}}">{{x.key}}</option>
              </select>
              </div>
            </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>


            <div class="form-group">
              <label class="col-sm-1 control-label">文件格式</label>
              <div class="col-sm-5">
              <select class="form-control " ng-model="contact.FileFormat" required >
               <option ng-repeat="x in FileFormats" value="{{x.value}}">{{x.key}}</option>
              </select>
              </div>
              <label  class="col-sm-1 control-label">视频编码</label>
              <div class="col-sm-5">
              <select class="form-control " ng-model="contact.VideoCodec" required >
               <option ng-repeat="x in VideoCodecs" value="{{x.value}}">{{x.key}}</option>
              </select>
              </div>
            </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>

          <div class="form-group">
            <label class="col-sm-1 controller-label">视频配置Profile</label>
            <div class="col-sm-5">
              <select class="form-control" ng-model="contact.VideoProfile" >
                <option ng-repeat="x in VideoProfiles" value="{{x.value}}">{{x.key}}</option>
              </select>
            </div>
            <label class="col-sm-1 controller-label">B帧数量</label>
            <div class="col-sm-5">
              <input type="Number" class="form-control" ng-model="contact.VideoBframe">
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>

          <div class="form-group">
            <label class="col-sm-1 control-label">宽度</label>
            <div class="col-sm-5">
              <input type="Number" name="VideoWidth" class="form-control" ng-model="contact.VideoWidth">
            </div>
            <label class="col-sm-1 control-label">高度</label>
            <div class="col-sm-5">
              <input type="Number" name="VideoHeight" class="form-control" ng-model="contact.VideoHeight">
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
          <div class="form-group">
            <label class="col-sm-1 control-label">显示比例</label>
            <div class="col-sm-5">
            <select class="form-control" ng-model="contact.VideoDar" required>
              <option ng-repeat="x in VideoDars" value="{{x.value}}">{{x.key}}</option>
            </select>
            </div>
            <label class="col-sm-1 control-label">视频帧率</label>
            <div class="col-sm-5">
              <input type="Number" name="VideoFrameRate" class="form-control" ng-model="contact.VideoFrameRate" maxlength="1000">
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
          <div class="form-group">
            <label class="col-sm-1 control-label">视频GOP</label>
            <div class="col-sm-5">
              <input type="Number" name="VideoGop" class="form-control" ng-model="contact.VideoGop">
            </div>
            <label class="col-sm-1 control-label">视频流比特率</label>
            <div class="col-sm-5">
              <input type="Number" name="VideoBitRate" class="form-control" ng-model="contact.VideoBitRate">
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
          <div class="form-group">
            <label class="col-sm-1 control-label">音频声道</label>
            <div class="col-sm-5">
              <select class="form-control" ng-model="contact.AudioChannel">
              <option ng-repeat="x in AudioChannels" value="{{x.value}}">{{x.key}}</option>
              </select>
            </div>
            <label class="col-sm-1 control-label">音频编码</label>
            <div class="col-sm-5">
              <select class="form-control" ng-model="contact.AudioCodec">
                <option ng-repeat="x in AudioCodecs" value="{{x.value}}">{{x.key}}</option>
              </select>
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
          <div class="form-group">
            <label class="col-sm-1 control-label">音频声道</label>
            <div class="col-sm-5">
              <input type="Number" name="AudioSamplingRate" class="form-control" ng-model="contact.AudioSamplingRate">
            </div>
            <label class="col-sm-1 control-label">音频编码</label>
            <div class="col-sm-5">
             <input type="Number" name="AudioBitRate" class="form-control" ng-model="contact.AudioBitRate">
            </div>
          </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
            <div class="form-group">
              <label class="col-sm-1 control-label">备注</label>  
              <div class="col-sm-10">
                 <textarea class="form-control" ng-model="contact.TemplateRemark"  rows="6" placeholder="备注"></textarea>
              </div>
            </div>
          <div class="line line-dashed b-b line-lg pull-in"></div>
        </div>


      <!--隐藏字段-->
    <input type="hidden"  ng-model="contact.Id"  >
    <input type="hidden"  ng-model="contact.AdderId"  >
    <input type="hidden"  ng-model="contact.AdderName"  >
    <input type="hidden"  ng-model="contact.AddTime"  >
    <input type="hidden"  ng-model="contact.UpdaterId"  >
    <input type="hidden"  ng-model="contact.UpdaterName"  >
    <input type="hidden"  ng-model="contact.UpdateTime"  >
    <input type="hidden"  ng-model="contact.DelFlag" ng-init="contact.DelFlag='0'" >
    <!--隐藏字段-->






            <footer class="panel-footer text-right bg-light lter">
              <button type="submit" class="btn btn-success">提交</button>
            </footer>
          </div>
        </form>
      </div>
    </div>
   
</div>
</div>




</div>
<!--angularjs-->
<script type="text/javascript">
app.controller('infoEditCtrl', function ($scope, $state, $stateParams,$http,$window) {
  //下拉框
  $scope.TemplateEnables = [
    {key : "启用", value : "1"},
    {key : "不启用", value : "0"}
  ];
  $scope.AutoTranscodes = [
    {key:"是",value:"1"},
    {key:"否",value:"0"}
  ];
  $scope.VideoDefinitions = [
    {key:"1080P",value:"1080P"},
    {key:"720P",value:"720P"},
    {key:"高清",value:"高清"},
    {key:"流畅",value:"流畅"},
    {key:"极速",value:"极速"},
    {key:"4K",value:"4K"},
    {key:"HD",value:"HD"},
    {key:"SD",value:"SD"}
  ];
  $scope.TaskPrioritys = [
    {key:"1",value:"1"},
    {key:"2",value:"2"},
    {key:"3",value:"3"},
    {key:"4",value:"4"},
    {key:"5",value:"5"},
    {key:"6",value:"6"},
    {key:"7",value:"7"},
    {key:"8",value:"8"},
    {key:"9",value:"9"},
    {key:"10",value:"10"}
  ];
  $scope.FileFormats = [
    {key:"mp4",value:".mp4"},
    {key:"flv",value:".flv"},
    {key:"m3u8",value:".m3u8"},
    {key:"wmv",value:".wmv"},
    {key:"其他",value:""}
  ];
  $scope.VideoCodecs = [
    {key:"H.264",value:"H.264"},
    {key:"H.265",value:"H.2645"}
  ];
  $scope.VideoProfiles = [
    {key:"High",value:"High"},
    {key:"Main",value:"Main"},
    {key:"Baseline",value:"Baseline"}
  ];
  $scope.VideoDars = [
    {key:"4:3",value:"4:3"},
    {key:"16:9",value:"16:9"},
    {key:"21:9",value:"21:9"}
  ];
  $scope.AudioChannels = [
    {key:"1",value:"1"},
    {key:"2",value:"2"},
    {key:"5.1",value:"5.1"}
  ];
  $scope.AudioCodecs = [
    {key:"AAC",value:"AAC"},
    {key:"MP3",value:"MP3"}
  ]

//返回按钮：开始
$scope.$window = $window;
    $scope.goBack = function() {
      $state.go('app.transcoding.transcoding');
    };


//返回按钮：结束

var infoId = $stateParams.infoId;
if(''!=infoId){
  var getInfoUrl = API_URL+"file_transcode_template?query=delflag:0,id:"+infoId+"&sortby=updateTime&order=desc"

  $http.get(getInfoUrl).success(function (response) {

     var obj = response[0];
     obj.VideoFrameRate = Number(obj.VideoFrameRate);
     $scope.contact = obj;
   })
 }

  //表单提交开始
$scope.processForm= function (){

//发起POST请求
var postInfoUrl = API_URL+"file_transcode_template";
var formData =  $scope.contact;
  //1.参数处理
    formData.AddTime = getNowDBFormatDate();
    formData.UpdateTime = getNowDBFormatDate();
    formData.AdderId = 1;
    formData.AdderName = '1';
    formData.UpdaterId = 1;
    formData.UpdaterName = '1';
    formData.VideoFrameRate = formData.VideoFrameRate+"";
   
    formData.TaskPriority = Number(formData.TaskPriority);

    
  if("undefined"!=typeof(formData.Id)){
    console.log(formData);
    alert("修改");
    $.ajax( {  
          async : false, //是否异步  
          cache : false, //是否使用缓存  
          type : 'put', //请求方式,post  
          dataType : "json", //数据传输格式  
          url : postInfoUrl+'/'+infoId, //请求链接  
          data: JSON.stringify(formData),
          error : function() {  
            console.log('亲，网络有点不给力呀！');  
          },  
          success : function(data) { 

            top.layer.msg('保存成功', {icon: 6});
         //2.成功跳转页面
         $state.go('app.transcoding.transcoding');
       }  
     }); 


  }else{
      alert("我是增加");
      console.log(JSON.stringify(formData));
    $.ajax( {  
          async : false, //是否异步  
          cache : false, //是否使用缓存  
          type : 'post', //请求方式,post  
          dataType : "json", //数据传输格式  
          url : postInfoUrl, //请求链接  
          data: JSON.stringify(formData),
          error : function() {  
            console.log('亲，网络有点不给力呀！');  
          },  
          success : function(data) { 

            top.layer.msg('保存成功', {icon: 6});
         //2.成功跳转页面
         $state.go('app.transcoding.transcoding');
       }  
     }); 

  }

}
 //表单提交结束

});
</script>
<!--angularjs-->









